{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Develop\\Anaconda3\\lib\\site-packages\\h5py\\__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  from ._conv import register_converters as _register_converters\n",
      "Using TensorFlow backend.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'channels_last'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"\"\"A very simple MNIST classifier.\n",
    "See extensive documentation at\n",
    "https://www.tensorflow.org/get_started/mnist/beginners\n",
    "\"\"\"\n",
    "from __future__ import absolute_import\n",
    "from __future__ import division\n",
    "from __future__ import print_function\n",
    "\n",
    "import argparse\n",
    "import sys\n",
    "\n",
    "from tensorflow.examples.tutorials.mnist import input_data\n",
    "\n",
    "import tensorflow as tf\n",
    "\n",
    "FLAGS = None\n",
    "\n",
    "from keras.layers.core import Dense, Flatten\n",
    "from keras.layers.convolutional import Conv2D\n",
    "from keras.layers.pooling import MaxPooling2D\n",
    "from keras.initializers import he_normal\n",
    "\n",
    "from keras import backend as K\n",
    "\n",
    "from keras.objectives import categorical_crossentropy\n",
    "\n",
    "import time\n",
    "import math\n",
    "\n",
    "K.image_data_format() "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "我们在这里调用系统提供的Mnist数据函数为我们读入数据，如果没有下载的话则进行下载。\n",
    "\n",
    "<font color=#ff0000>**这里将data_dir改为适合你的运行环境的目录**</font>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From <ipython-input-2-698ada706af1>:3: read_data_sets (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use alternatives such as official/mnist/dataset.py from tensorflow/models.\n",
      "WARNING:tensorflow:From D:\\Develop\\Anaconda3\\lib\\site-packages\\tensorflow\\contrib\\learn\\python\\learn\\datasets\\mnist.py:260: maybe_download (from tensorflow.contrib.learn.python.learn.datasets.base) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please write your own downloading logic.\n",
      "WARNING:tensorflow:From D:\\Develop\\Anaconda3\\lib\\site-packages\\tensorflow\\contrib\\learn\\python\\learn\\datasets\\mnist.py:262: extract_images (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use tf.data to implement this functionality.\n",
      "Extracting /tmp/tensorflow/mnist/input_data\\train-images-idx3-ubyte.gz\n",
      "WARNING:tensorflow:From D:\\Develop\\Anaconda3\\lib\\site-packages\\tensorflow\\contrib\\learn\\python\\learn\\datasets\\mnist.py:267: extract_labels (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use tf.data to implement this functionality.\n",
      "Extracting /tmp/tensorflow/mnist/input_data\\train-labels-idx1-ubyte.gz\n",
      "WARNING:tensorflow:From D:\\Develop\\Anaconda3\\lib\\site-packages\\tensorflow\\contrib\\learn\\python\\learn\\datasets\\mnist.py:110: dense_to_one_hot (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use tf.one_hot on tensors.\n",
      "Extracting /tmp/tensorflow/mnist/input_data\\t10k-images-idx3-ubyte.gz\n",
      "Extracting /tmp/tensorflow/mnist/input_data\\t10k-labels-idx1-ubyte.gz\n",
      "WARNING:tensorflow:From D:\\Develop\\Anaconda3\\lib\\site-packages\\tensorflow\\contrib\\learn\\python\\learn\\datasets\\mnist.py:290: DataSet.__init__ (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use alternatives such as official/mnist/dataset.py from tensorflow/models.\n"
     ]
    }
   ],
   "source": [
    "# Import data\n",
    "data_dir = '/tmp/tensorflow/mnist/input_data'\n",
    "mnist = input_data.read_data_sets(data_dir, one_hot=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "一个非常非常简陋的模型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create the model\n",
    "x = tf.placeholder(tf.float32, [None, 784])\n",
    "# 定义学习率\n",
    "learning_rate = tf.placeholder(tf.float32)\n",
    "# 定义我们的ground truth 占位符\n",
    "y_ = tf.placeholder(tf.float32, [None, 10])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "定义我们的ground truth 占位符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Define loss and optimizer\n",
    "y_ = tf.placeholder(tf.float32, [None, 10])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# reshape\n",
    "x_image = tf.reshape(x, [-1, 28, 28, 1])\n",
    "# Relu激活函数搭配He函数初始化\n",
    "kernel_initializer = he_normal(seed=None)\n",
    "bias_initializer = he_normal(seed=None)\n",
    "net = Conv2D(32, kernel_size=[5,5], strides=[1,1],activation='relu',\n",
    "                 padding='same',kernel_initializer=kernel_initializer, bias_initializer=bias_initializer,\n",
    "                input_shape=[28,28,1])(x_image)\n",
    "net = MaxPooling2D(pool_size=[2,2])(net)\n",
    "net = Conv2D(64, kernel_size=[5,5], strides=[1,1],activation='relu',\n",
    "             kernel_initializer=kernel_initializer, bias_initializer=bias_initializer,\n",
    "             padding='same')(net)\n",
    "net = MaxPooling2D(pool_size=[2,2])(net)\n",
    "net = Flatten()(net)\n",
    "length = 572\n",
    "# length = 1000\n",
    "net = Dense(length, activation='relu')(net)\n",
    "net = Dense(10,activation='softmax')(net)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 计算交叉熵\n",
    "cross_entropy = tf.reduce_mean(categorical_crossentropy(y_, net))\n",
    "# 计算l2损失\n",
    "l2_loss = tf.add_n( [tf.nn.l2_loss(w) for w in tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES)] )\n",
    "# 计算带有L2正则项的损失函数\n",
    "total_loss = cross_entropy + 7e-5*l2_loss"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "生成一个训练step"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "train_step = tf.train.GradientDescentOptimizer(learning_rate).minimize(total_loss)\n",
    "\n",
    "sess = tf.Session()\n",
    "K.set_session(sess)\n",
    "init_op = tf.global_variables_initializer()\n",
    "sess.run(init_op)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 定义计算正确率的函数\n",
    "def get_accuracy(x, y, t):\n",
    "    correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(t, 1))\n",
    "    accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))\n",
    "    return sess.run(accuracy, feed_dict={x: mnist.test.images, t: mnist.test.labels})"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "在这里我们仍然调用系统提供的读取数据，为我们取得一个batch。\n",
    "然后我们运行6k个step(10 epochs)，对权重进行优化。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "当前第9回合，accuracy=0.9621999859809875,cost_time=27\n",
      "当前第19回合，accuracy=0.9535999894142151,cost_time=54\n",
      "当前第29回合，accuracy=0.9664000272750854,cost_time=81\n",
      "当前第39回合，accuracy=0.9617999792098999,cost_time=108\n",
      "当前第49回合，accuracy=0.9646000266075134,cost_time=136\n",
      "当前第59回合，accuracy=0.9656999707221985,cost_time=163\n",
      "当前第69回合，accuracy=0.9599999785423279,cost_time=190\n",
      "当前第79回合，accuracy=0.9667999744415283,cost_time=217\n",
      "当前第89回合，accuracy=0.963100016117096,cost_time=245\n",
      "当前第99回合，accuracy=0.9660999774932861,cost_time=272\n",
      "当前第109回合，accuracy=0.9671000242233276,cost_time=300\n",
      "当前第119回合，accuracy=0.9726999998092651,cost_time=327\n",
      "当前第129回合，accuracy=0.9627000093460083,cost_time=355\n",
      "当前第139回合，accuracy=0.9725000262260437,cost_time=383\n",
      "当前第149回合，accuracy=0.9753999710083008,cost_time=410\n",
      "当前第159回合，accuracy=0.9739000201225281,cost_time=437\n",
      "当前第169回合，accuracy=0.974399983882904,cost_time=464\n",
      "当前第179回合，accuracy=0.9757000207901001,cost_time=492\n",
      "当前第189回合，accuracy=0.9718000292778015,cost_time=519\n",
      "当前第199回合，accuracy=0.9778000116348267,cost_time=547\n",
      "当前第209回合，accuracy=0.9757000207901001,cost_time=573\n",
      "当前第219回合，accuracy=0.9790999889373779,cost_time=602\n",
      "当前第229回合，accuracy=0.9772999882698059,cost_time=630\n",
      "当前第239回合，accuracy=0.9732000231742859,cost_time=656\n",
      "当前第249回合，accuracy=0.9747999906539917,cost_time=681\n",
      "当前第259回合，accuracy=0.9732999801635742,cost_time=706\n",
      "当前第269回合，accuracy=0.9801999926567078,cost_time=731\n",
      "当前第279回合，accuracy=0.9753999710083008,cost_time=757\n",
      "当前第289回合，accuracy=0.9799000024795532,cost_time=782\n",
      "当前第299回合，accuracy=0.9763000011444092,cost_time=807\n",
      "当前第309回合，accuracy=0.9800999760627747,cost_time=832\n",
      "当前第319回合，accuracy=0.9793999791145325,cost_time=858\n",
      "当前第329回合，accuracy=0.9794999957084656,cost_time=882\n",
      "当前第339回合，accuracy=0.9496999979019165,cost_time=907\n",
      "当前第349回合，accuracy=0.9797999858856201,cost_time=932\n",
      "当前第359回合，accuracy=0.9828000068664551,cost_time=957\n",
      "当前第369回合，accuracy=0.9822999835014343,cost_time=982\n",
      "当前第379回合，accuracy=0.9824000000953674,cost_time=1007\n",
      "当前第389回合，accuracy=0.9785000085830688,cost_time=1033\n",
      "当前第399回合，accuracy=0.9745000004768372,cost_time=1057\n",
      "当前第409回合，accuracy=0.9772999882698059,cost_time=1082\n",
      "当前第419回合，accuracy=0.9807999730110168,cost_time=1107\n",
      "当前第429回合，accuracy=0.9807999730110168,cost_time=1131\n",
      "当前第439回合，accuracy=0.9776999950408936,cost_time=1157\n",
      "当前第449回合，accuracy=0.980400025844574,cost_time=1181\n",
      "当前第459回合，accuracy=0.9789000153541565,cost_time=1207\n",
      "当前第469回合，accuracy=0.9799000024795532,cost_time=1233\n",
      "当前第479回合，accuracy=0.9821000099182129,cost_time=1258\n",
      "当前第489回合，accuracy=0.9801999926567078,cost_time=1287\n",
      "当前第499回合，accuracy=0.984499990940094,cost_time=1314\n",
      "当前第509回合，accuracy=0.982699990272522,cost_time=1338\n",
      "当前第519回合，accuracy=0.9822999835014343,cost_time=1364\n",
      "当前第529回合，accuracy=0.984000027179718,cost_time=1390\n",
      "当前第539回合，accuracy=0.9829000234603882,cost_time=1414\n",
      "当前第549回合，accuracy=0.9817000031471252,cost_time=1439\n",
      "当前第559回合，accuracy=0.9848999977111816,cost_time=1464\n",
      "当前第569回合，accuracy=0.9810000061988831,cost_time=1489\n",
      "当前第579回合，accuracy=0.9835000038146973,cost_time=1517\n",
      "当前第589回合，accuracy=0.9857000112533569,cost_time=1542\n",
      "当前第599回合，accuracy=0.9793999791145325,cost_time=1567\n",
      "当前第609回合，accuracy=0.9667999744415283,cost_time=1592\n",
      "当前第619回合，accuracy=0.9832000136375427,cost_time=1617\n",
      "当前第629回合，accuracy=0.9821000099182129,cost_time=1642\n",
      "当前第639回合，accuracy=0.9797999858856201,cost_time=1667\n",
      "当前第649回合，accuracy=0.9829000234603882,cost_time=1693\n",
      "当前第659回合，accuracy=0.9836000204086304,cost_time=1718\n",
      "当前第669回合，accuracy=0.984000027179718,cost_time=1744\n",
      "当前第679回合，accuracy=0.9833999872207642,cost_time=1770\n",
      "当前第689回合，accuracy=0.9837999939918518,cost_time=1795\n",
      "当前第699回合，accuracy=0.9805999994277954,cost_time=1820\n",
      "当前第709回合，accuracy=0.9819999933242798,cost_time=1846\n",
      "当前第719回合，accuracy=0.984499990940094,cost_time=1871\n",
      "当前第729回合，accuracy=0.9854999780654907,cost_time=1896\n",
      "当前第739回合，accuracy=0.9864000082015991,cost_time=1922\n",
      "当前第749回合，accuracy=0.9855999946594238,cost_time=1948\n",
      "当前第759回合，accuracy=0.9853000044822693,cost_time=1973\n",
      "当前第769回合，accuracy=0.982699990272522,cost_time=1999\n",
      "当前第779回合，accuracy=0.9853000044822693,cost_time=2024\n",
      "当前第789回合，accuracy=0.986299991607666,cost_time=2049\n",
      "当前第799回合，accuracy=0.9878000020980835,cost_time=2075\n",
      "当前第809回合，accuracy=0.9873999953269958,cost_time=2100\n",
      "当前第819回合，accuracy=0.9843000173568726,cost_time=2128\n",
      "当前第829回合，accuracy=0.9854999780654907,cost_time=2160\n",
      "当前第839回合，accuracy=0.9843999743461609,cost_time=2190\n",
      "当前第849回合，accuracy=0.9829999804496765,cost_time=2219\n",
      "当前第859回合，accuracy=0.9807999730110168,cost_time=2247\n",
      "当前第869回合，accuracy=0.9876999855041504,cost_time=2277\n",
      "当前第879回合，accuracy=0.9865999817848206,cost_time=2307\n",
      "当前第889回合，accuracy=0.9858999848365784,cost_time=2337\n",
      "当前第899回合，accuracy=0.9876999855041504,cost_time=2367\n",
      "当前第909回合，accuracy=0.9842000007629395,cost_time=2394\n",
      "当前第919回合，accuracy=0.9871000051498413,cost_time=2423\n",
      "当前第929回合，accuracy=0.9886000156402588,cost_time=2451\n",
      "当前第939回合，accuracy=0.9882000088691711,cost_time=2479\n",
      "当前第949回合，accuracy=0.9876000285148621,cost_time=2507\n",
      "当前第959回合，accuracy=0.9853000044822693,cost_time=2534\n",
      "当前第969回合，accuracy=0.9850999712944031,cost_time=2560\n",
      "当前第979回合，accuracy=0.9832000136375427,cost_time=2589\n",
      "当前第989回合，accuracy=0.9884999990463257,cost_time=2617\n",
      "当前第999回合，accuracy=0.9854000210762024,cost_time=2646\n",
      "当前第1009回合，accuracy=0.9868000149726868,cost_time=2676\n",
      "当前第1019回合，accuracy=0.9878000020980835,cost_time=2706\n",
      "当前第1029回合，accuracy=0.988099992275238,cost_time=2734\n",
      "当前第1039回合，accuracy=0.9876999855041504,cost_time=2762\n",
      "当前第1049回合，accuracy=0.9879999756813049,cost_time=2791\n",
      "当前第1059回合，accuracy=0.9883000254631042,cost_time=2821\n",
      "当前第1069回合，accuracy=0.989300012588501,cost_time=2848\n",
      "当前第1079回合，accuracy=0.9872999787330627,cost_time=2879\n",
      "当前第1089回合，accuracy=0.9876000285148621,cost_time=2906\n",
      "当前第1099回合，accuracy=0.9866999983787537,cost_time=2935\n",
      "当前第1109回合，accuracy=0.9836999773979187,cost_time=2962\n",
      "当前第1119回合，accuracy=0.9882000088691711,cost_time=2991\n",
      "当前第1129回合，accuracy=0.9873999953269958,cost_time=3024\n",
      "当前第1139回合，accuracy=0.9872999787330627,cost_time=3057\n",
      "当前第1149回合，accuracy=0.9882000088691711,cost_time=3089\n",
      "当前第1159回合，accuracy=0.988099992275238,cost_time=3122\n",
      "当前第1169回合，accuracy=0.9854999780654907,cost_time=3155\n",
      "当前第1179回合，accuracy=0.9865999817848206,cost_time=3187\n",
      "当前第1189回合，accuracy=0.988099992275238,cost_time=3219\n",
      "当前第1199回合，accuracy=0.9861000180244446,cost_time=3253\n",
      "当前第1209回合，accuracy=0.9865000247955322,cost_time=3287\n",
      "当前第1219回合，accuracy=0.9843000173568726,cost_time=3321\n",
      "当前第1229回合，accuracy=0.9866999983787537,cost_time=3355\n",
      "当前第1239回合，accuracy=0.9868999719619751,cost_time=3388\n",
      "当前第1249回合，accuracy=0.986299991607666,cost_time=3422\n",
      "当前第1259回合，accuracy=0.9857000112533569,cost_time=3457\n",
      "当前第1269回合，accuracy=0.9889000058174133,cost_time=3491\n",
      "当前第1279回合，accuracy=0.9868999719619751,cost_time=3524\n",
      "当前第1289回合，accuracy=0.9868000149726868,cost_time=3558\n",
      "当前第1299回合，accuracy=0.9868999719619751,cost_time=3591\n",
      "当前第1309回合，accuracy=0.9890999794006348,cost_time=3624\n",
      "当前第1319回合，accuracy=0.9878000020980835,cost_time=3658\n",
      "当前第1329回合，accuracy=0.9890000224113464,cost_time=3691\n",
      "当前第1339回合，accuracy=0.9889000058174133,cost_time=3724\n",
      "当前第1349回合，accuracy=0.9883999824523926,cost_time=3757\n",
      "当前第1359回合，accuracy=0.9836000204086304,cost_time=3789\n",
      "当前第1369回合，accuracy=0.9894000291824341,cost_time=3822\n",
      "当前第1379回合，accuracy=0.9901000261306763,cost_time=3856\n",
      "当前第1389回合，accuracy=0.9858999848365784,cost_time=3889\n",
      "当前第1399回合，accuracy=0.9882000088691711,cost_time=3924\n",
      "当前第1409回合，accuracy=0.9894000291824341,cost_time=3959\n",
      "当前第1419回合，accuracy=0.9871000051498413,cost_time=3991\n",
      "当前第1429回合，accuracy=0.9857000112533569,cost_time=4022\n",
      "当前第1439回合，accuracy=0.9905999898910522,cost_time=4057\n",
      "当前第1449回合，accuracy=0.9873999953269958,cost_time=4091\n",
      "当前第1459回合，accuracy=0.9894000291824341,cost_time=4124\n",
      "当前第1469回合，accuracy=0.9886999726295471,cost_time=4156\n",
      "当前第1479回合，accuracy=0.9886000156402588,cost_time=4188\n",
      "当前第1489回合，accuracy=0.9886999726295471,cost_time=4221\n",
      "当前第1499回合，accuracy=0.988099992275238,cost_time=4254\n",
      "当前第1509回合，accuracy=0.9868999719619751,cost_time=4287\n",
      "当前第1519回合，accuracy=0.9897000193595886,cost_time=4320\n",
      "当前第1529回合，accuracy=0.9900000095367432,cost_time=4354\n",
      "当前第1539回合，accuracy=0.9886999726295471,cost_time=4386\n",
      "当前第1549回合，accuracy=0.989300012588501,cost_time=4419\n",
      "当前第1559回合，accuracy=0.9873999953269958,cost_time=4453\n",
      "当前第1569回合，accuracy=0.9872999787330627,cost_time=4486\n",
      "当前第1579回合，accuracy=0.987500011920929,cost_time=4519\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "当前第1589回合，accuracy=0.9886000156402588,cost_time=4553\n",
      "当前第1599回合，accuracy=0.9901000261306763,cost_time=4586\n",
      "当前第1609回合，accuracy=0.9865999817848206,cost_time=4619\n",
      "当前第1619回合，accuracy=0.9883000254631042,cost_time=4650\n",
      "当前第1629回合，accuracy=0.989799976348877,cost_time=4681\n",
      "当前第1639回合，accuracy=0.9901000261306763,cost_time=4712\n",
      "当前第1649回合，accuracy=0.9886999726295471,cost_time=4740\n",
      "当前第1659回合，accuracy=0.9911999702453613,cost_time=4771\n",
      "当前第1669回合，accuracy=0.9905999898910522,cost_time=4802\n",
      "当前第1679回合，accuracy=0.9868999719619751,cost_time=4831\n",
      "当前第1689回合，accuracy=0.98580002784729,cost_time=4860\n",
      "当前第1699回合，accuracy=0.9883999824523926,cost_time=4890\n",
      "当前第1709回合，accuracy=0.9873999953269958,cost_time=4920\n",
      "当前第1719回合，accuracy=0.9891999959945679,cost_time=4950\n",
      "当前第1729回合，accuracy=0.9861000180244446,cost_time=4986\n",
      "当前第1739回合，accuracy=0.9900000095367432,cost_time=5022\n",
      "当前第1749回合，accuracy=0.9884999990463257,cost_time=5056\n",
      "当前第1759回合，accuracy=0.9891999959945679,cost_time=5088\n",
      "当前第1769回合，accuracy=0.9900000095367432,cost_time=5120\n",
      "当前第1779回合，accuracy=0.9908000230789185,cost_time=5153\n",
      "当前第1789回合，accuracy=0.9890999794006348,cost_time=5186\n",
      "当前第1799回合，accuracy=0.9901999831199646,cost_time=5218\n",
      "当前第1809回合，accuracy=0.9882000088691711,cost_time=5251\n",
      "当前第1819回合，accuracy=0.9876000285148621,cost_time=5285\n",
      "当前第1829回合，accuracy=0.9907000064849854,cost_time=5315\n",
      "当前第1839回合，accuracy=0.9889000058174133,cost_time=5345\n",
      "当前第1849回合，accuracy=0.9897000193595886,cost_time=5375\n",
      "当前第1859回合，accuracy=0.9909999966621399,cost_time=5407\n",
      "当前第1869回合，accuracy=0.9901000261306763,cost_time=5436\n",
      "当前第1879回合，accuracy=0.9879999756813049,cost_time=5464\n",
      "当前第1889回合，accuracy=0.989300012588501,cost_time=5494\n",
      "当前第1899回合，accuracy=0.989799976348877,cost_time=5522\n",
      "当前第1909回合，accuracy=0.9876999855041504,cost_time=5552\n",
      "当前第1919回合，accuracy=0.9896000027656555,cost_time=5585\n",
      "当前第1929回合，accuracy=0.9896000027656555,cost_time=5614\n",
      "当前第1939回合，accuracy=0.9909999966621399,cost_time=5645\n",
      "当前第1949回合，accuracy=0.9908999800682068,cost_time=5675\n",
      "当前第1959回合，accuracy=0.9898999929428101,cost_time=5704\n",
      "当前第1969回合，accuracy=0.9890000224113464,cost_time=5734\n",
      "当前第1979回合，accuracy=0.9854000210762024,cost_time=5763\n",
      "当前第1989回合，accuracy=0.9889000058174133,cost_time=5794\n",
      "当前第1999回合，accuracy=0.989300012588501,cost_time=5823\n",
      "当前第2009回合，accuracy=0.9896000027656555,cost_time=5851\n",
      "当前第2019回合，accuracy=0.9905999898910522,cost_time=5879\n",
      "当前第2029回合，accuracy=0.9904000163078308,cost_time=5907\n",
      "当前第2039回合，accuracy=0.987500011920929,cost_time=5935\n",
      "当前第2049回合，accuracy=0.9879999756813049,cost_time=5963\n",
      "当前第2059回合，accuracy=0.9912999868392944,cost_time=5991\n",
      "当前第2069回合，accuracy=0.9907000064849854,cost_time=6019\n",
      "当前第2079回合，accuracy=0.991599977016449,cost_time=6046\n",
      "当前第2089回合，accuracy=0.9908999800682068,cost_time=6074\n",
      "当前第2099回合，accuracy=0.9908000230789185,cost_time=6102\n",
      "当前第2109回合，accuracy=0.9894999861717224,cost_time=6129\n",
      "当前第2119回合，accuracy=0.9902999997138977,cost_time=6156\n",
      "当前第2129回合，accuracy=0.9909999966621399,cost_time=6186\n",
      "当前第2139回合，accuracy=0.9908999800682068,cost_time=6213\n",
      "当前第2149回合，accuracy=0.9886000156402588,cost_time=6244\n",
      "当前第2159回合，accuracy=0.9886000156402588,cost_time=6277\n",
      "当前第2169回合，accuracy=0.991599977016449,cost_time=6308\n",
      "当前第2179回合，accuracy=0.9894000291824341,cost_time=6337\n",
      "当前第2189回合，accuracy=0.9922000169754028,cost_time=6366\n",
      "当前第2199回合，accuracy=0.9923999905586243,cost_time=6395\n",
      "当前第2209回合，accuracy=0.9887999892234802,cost_time=6429\n",
      "当前第2219回合，accuracy=0.991100013256073,cost_time=6462\n",
      "当前第2229回合，accuracy=0.9901999831199646,cost_time=6494\n",
      "当前第2239回合，accuracy=0.9897000193595886,cost_time=6524\n",
      "当前第2249回合，accuracy=0.989799976348877,cost_time=6558\n",
      "当前第2259回合，accuracy=0.9902999997138977,cost_time=6591\n",
      "当前第2269回合，accuracy=0.9907000064849854,cost_time=6621\n",
      "当前第2279回合，accuracy=0.989799976348877,cost_time=6651\n",
      "当前第2289回合，accuracy=0.9904999732971191,cost_time=6681\n",
      "当前第2299回合，accuracy=0.9909999966621399,cost_time=6712\n",
      "当前第2309回合，accuracy=0.9902999997138977,cost_time=6744\n",
      "当前第2319回合，accuracy=0.9914000034332275,cost_time=6776\n",
      "当前第2329回合，accuracy=0.9907000064849854,cost_time=6807\n",
      "当前第2339回合，accuracy=0.9911999702453613,cost_time=6841\n",
      "当前第2349回合，accuracy=0.9883999824523926,cost_time=6870\n",
      "当前第2359回合，accuracy=0.9894000291824341,cost_time=6899\n",
      "当前第2369回合，accuracy=0.9909999966621399,cost_time=6929\n",
      "当前第2379回合，accuracy=0.9907000064849854,cost_time=6958\n",
      "当前第2389回合，accuracy=0.9908000230789185,cost_time=6987\n",
      "当前第2399回合，accuracy=0.991100013256073,cost_time=7016\n",
      "当前第2409回合，accuracy=0.988099992275238,cost_time=7050\n",
      "当前第2419回合，accuracy=0.9909999966621399,cost_time=7080\n",
      "当前第2429回合，accuracy=0.9915000200271606,cost_time=7111\n",
      "当前第2439回合，accuracy=0.9901999831199646,cost_time=7140\n",
      "当前第2449回合，accuracy=0.9909999966621399,cost_time=7171\n",
      "当前第2459回合，accuracy=0.9865999817848206,cost_time=7200\n",
      "当前第2469回合，accuracy=0.9898999929428101,cost_time=7229\n",
      "当前第2479回合，accuracy=0.9900000095367432,cost_time=7258\n",
      "当前第2489回合，accuracy=0.9894000291824341,cost_time=7288\n",
      "当前第2499回合，accuracy=0.9914000034332275,cost_time=7319\n",
      "当前第2509回合，accuracy=0.9901999831199646,cost_time=7346\n",
      "当前第2519回合，accuracy=0.9900000095367432,cost_time=7374\n",
      "当前第2529回合，accuracy=0.9905999898910522,cost_time=7402\n",
      "当前第2539回合，accuracy=0.9894000291824341,cost_time=7429\n",
      "当前第2549回合，accuracy=0.9836000204086304,cost_time=7457\n",
      "当前第2559回合，accuracy=0.9857000112533569,cost_time=7485\n",
      "当前第2569回合，accuracy=0.9898999929428101,cost_time=7512\n",
      "当前第2579回合，accuracy=0.9907000064849854,cost_time=7539\n",
      "当前第2589回合，accuracy=0.9915000200271606,cost_time=7566\n",
      "当前第2599回合，accuracy=0.9916999936103821,cost_time=7594\n",
      "当前第2609回合，accuracy=0.9901999831199646,cost_time=7621\n",
      "当前第2619回合，accuracy=0.9914000034332275,cost_time=7648\n",
      "当前第2629回合，accuracy=0.991100013256073,cost_time=7676\n",
      "当前第2639回合，accuracy=0.9916999936103821,cost_time=7703\n",
      "当前第2649回合，accuracy=0.9918000102043152,cost_time=7730\n",
      "当前第2659回合，accuracy=0.9921000003814697,cost_time=7757\n",
      "当前第2669回合，accuracy=0.9908000230789185,cost_time=7784\n",
      "当前第2679回合，accuracy=0.9919000267982483,cost_time=7812\n",
      "当前第2689回合，accuracy=0.9840999841690063,cost_time=7840\n",
      "当前第2699回合，accuracy=0.9921000003814697,cost_time=7868\n",
      "当前第2709回合，accuracy=0.9915000200271606,cost_time=7895\n",
      "当前第2719回合，accuracy=0.9908000230789185,cost_time=7922\n",
      "当前第2729回合，accuracy=0.9908000230789185,cost_time=7949\n",
      "当前第2739回合，accuracy=0.9922000169754028,cost_time=7975\n",
      "当前第2749回合，accuracy=0.9894999861717224,cost_time=8000\n",
      "当前第2759回合，accuracy=0.9907000064849854,cost_time=8026\n",
      "当前第2769回合，accuracy=0.991100013256073,cost_time=8052\n",
      "当前第2779回合，accuracy=0.9909999966621399,cost_time=8078\n",
      "当前第2789回合，accuracy=0.9898999929428101,cost_time=8103\n",
      "当前第2799回合，accuracy=0.9911999702453613,cost_time=8128\n",
      "当前第2809回合，accuracy=0.9925000071525574,cost_time=8154\n",
      "当前第2819回合，accuracy=0.9915000200271606,cost_time=8181\n",
      "当前第2829回合，accuracy=0.991100013256073,cost_time=8206\n",
      "当前第2839回合，accuracy=0.9905999898910522,cost_time=8232\n",
      "当前第2849回合，accuracy=0.991599977016449,cost_time=8257\n",
      "当前第2859回合，accuracy=0.9908000230789185,cost_time=8283\n",
      "当前第2869回合，accuracy=0.9921000003814697,cost_time=8308\n",
      "当前第2879回合，accuracy=0.9914000034332275,cost_time=8334\n",
      "当前第2889回合，accuracy=0.9900000095367432,cost_time=8360\n",
      "当前第2899回合，accuracy=0.9904000163078308,cost_time=8385\n",
      "当前第2909回合，accuracy=0.9897000193595886,cost_time=8411\n",
      "当前第2919回合，accuracy=0.9908000230789185,cost_time=8437\n",
      "当前第2929回合，accuracy=0.9921000003814697,cost_time=8464\n",
      "当前第2939回合，accuracy=0.9904000163078308,cost_time=8499\n",
      "当前第2949回合，accuracy=0.9908000230789185,cost_time=8529\n",
      "当前第2959回合，accuracy=0.9915000200271606,cost_time=8560\n",
      "当前第2969回合，accuracy=0.9914000034332275,cost_time=8590\n",
      "当前第2979回合，accuracy=0.9890000224113464,cost_time=8621\n",
      "当前第2989回合，accuracy=0.9908000230789185,cost_time=8654\n",
      "当前第2999回合，accuracy=0.9907000064849854,cost_time=8687\n",
      "当前第3009回合，accuracy=0.9919000267982483,cost_time=8718\n",
      "当前第3019回合，accuracy=0.991599977016449,cost_time=8750\n",
      "当前第3029回合，accuracy=0.9908000230789185,cost_time=8782\n",
      "当前第3039回合，accuracy=0.9916999936103821,cost_time=8812\n",
      "当前第3049回合，accuracy=0.9883000254631042,cost_time=8844\n",
      "当前第3059回合，accuracy=0.989300012588501,cost_time=8876\n",
      "当前第3069回合，accuracy=0.991599977016449,cost_time=8906\n",
      "当前第3079回合，accuracy=0.9919000267982483,cost_time=8936\n",
      "当前第3089回合，accuracy=0.9873999953269958,cost_time=8966\n",
      "当前第3099回合，accuracy=0.9915000200271606,cost_time=8996\n",
      "当前第3109回合，accuracy=0.9909999966621399,cost_time=9026\n",
      "当前第3119回合，accuracy=0.9927999973297119,cost_time=9057\n",
      "当前第3129回合，accuracy=0.989799976348877,cost_time=9088\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "当前第3139回合，accuracy=0.9901999831199646,cost_time=9118\n",
      "当前第3149回合，accuracy=0.9886999726295471,cost_time=9149\n",
      "当前第3159回合，accuracy=0.9916999936103821,cost_time=9179\n",
      "当前第3169回合，accuracy=0.9914000034332275,cost_time=9210\n",
      "当前第3179回合，accuracy=0.9907000064849854,cost_time=9240\n",
      "当前第3189回合，accuracy=0.991599977016449,cost_time=9271\n",
      "当前第3199回合，accuracy=0.9902999997138977,cost_time=9302\n",
      "当前第3209回合，accuracy=0.9922999739646912,cost_time=9334\n",
      "当前第3219回合，accuracy=0.9916999936103821,cost_time=9366\n",
      "当前第3229回合，accuracy=0.9908999800682068,cost_time=9397\n",
      "当前第3239回合，accuracy=0.9914000034332275,cost_time=9427\n",
      "当前第3249回合，accuracy=0.9919000267982483,cost_time=9462\n",
      "当前第3259回合，accuracy=0.9908999800682068,cost_time=9497\n",
      "当前第3269回合，accuracy=0.9925000071525574,cost_time=9529\n",
      "当前第3279回合，accuracy=0.9926000237464905,cost_time=9561\n",
      "当前第3289回合，accuracy=0.9898999929428101,cost_time=9592\n",
      "当前第3299回合，accuracy=0.9922000169754028,cost_time=9625\n",
      "当前第3309回合，accuracy=0.9922999739646912,cost_time=9657\n",
      "当前第3319回合，accuracy=0.9919999837875366,cost_time=9688\n",
      "当前第3329回合，accuracy=0.9923999905586243,cost_time=9719\n",
      "当前第3339回合，accuracy=0.9905999898910522,cost_time=9749\n",
      "当前第3349回合，accuracy=0.9911999702453613,cost_time=9782\n",
      "当前第3359回合，accuracy=0.9925000071525574,cost_time=9815\n",
      "当前第3369回合，accuracy=0.9911999702453613,cost_time=9848\n",
      "当前第3379回合，accuracy=0.9909999966621399,cost_time=9881\n",
      "当前第3389回合，accuracy=0.9900000095367432,cost_time=9911\n",
      "当前第3399回合，accuracy=0.9900000095367432,cost_time=9940\n",
      "当前第3409回合，accuracy=0.9912999868392944,cost_time=9971\n",
      "当前第3419回合，accuracy=0.9919000267982483,cost_time=10001\n",
      "当前第3429回合，accuracy=0.9911999702453613,cost_time=10030\n",
      "当前第3439回合，accuracy=0.9904999732971191,cost_time=10060\n",
      "当前第3449回合，accuracy=0.9912999868392944,cost_time=10089\n",
      "当前第3459回合，accuracy=0.9908000230789185,cost_time=10118\n",
      "当前第3469回合，accuracy=0.9921000003814697,cost_time=10146\n",
      "当前第3479回合，accuracy=0.9912999868392944,cost_time=10174\n",
      "当前第3489回合，accuracy=0.991599977016449,cost_time=10203\n",
      "当前第3499回合，accuracy=0.9911999702453613,cost_time=10232\n",
      "当前第3509回合，accuracy=0.9907000064849854,cost_time=10262\n",
      "当前第3519回合，accuracy=0.9890999794006348,cost_time=10291\n",
      "当前第3529回合，accuracy=0.9904000163078308,cost_time=10321\n",
      "当前第3539回合，accuracy=0.9918000102043152,cost_time=10349\n",
      "当前第3549回合，accuracy=0.9912999868392944,cost_time=10379\n",
      "当前第3559回合，accuracy=0.9921000003814697,cost_time=10407\n",
      "当前第3569回合，accuracy=0.9926000237464905,cost_time=10437\n",
      "当前第3579回合，accuracy=0.9912999868392944,cost_time=10468\n",
      "当前第3589回合，accuracy=0.9918000102043152,cost_time=10500\n",
      "当前第3599回合，accuracy=0.9926000237464905,cost_time=10530\n",
      "当前第3609回合，accuracy=0.9898999929428101,cost_time=10562\n",
      "当前第3619回合，accuracy=0.9915000200271606,cost_time=10592\n",
      "当前第3629回合，accuracy=0.9915000200271606,cost_time=10624\n",
      "当前第3639回合，accuracy=0.991100013256073,cost_time=10655\n",
      "当前第3649回合，accuracy=0.991599977016449,cost_time=10688\n",
      "当前第3659回合，accuracy=0.9907000064849854,cost_time=10719\n",
      "当前第3669回合，accuracy=0.9896000027656555,cost_time=10749\n",
      "当前第3679回合，accuracy=0.9894999861717224,cost_time=10780\n",
      "当前第3689回合，accuracy=0.9916999936103821,cost_time=10810\n",
      "当前第3699回合，accuracy=0.9919999837875366,cost_time=10841\n",
      "当前第3709回合，accuracy=0.9912999868392944,cost_time=10870\n",
      "当前第3719回合，accuracy=0.9926999807357788,cost_time=10901\n",
      "当前第3729回合，accuracy=0.9927999973297119,cost_time=10936\n",
      "当前第3739回合，accuracy=0.9925000071525574,cost_time=10978\n",
      "当前第3749回合，accuracy=0.9926000237464905,cost_time=11014\n",
      "当前第3759回合，accuracy=0.9914000034332275,cost_time=11049\n",
      "当前第3769回合，accuracy=0.9922999739646912,cost_time=11081\n",
      "当前第3779回合，accuracy=0.9933000206947327,cost_time=11113\n",
      "当前第3789回合，accuracy=0.9922999739646912,cost_time=11145\n",
      "当前第3799回合，accuracy=0.9922000169754028,cost_time=11177\n",
      "当前第3809回合，accuracy=0.9921000003814697,cost_time=11211\n",
      "当前第3819回合，accuracy=0.9923999905586243,cost_time=11248\n",
      "当前第3829回合，accuracy=0.9907000064849854,cost_time=11280\n",
      "当前第3839回合，accuracy=0.9908000230789185,cost_time=11311\n",
      "当前第3849回合，accuracy=0.9926000237464905,cost_time=11345\n",
      "当前第3859回合，accuracy=0.9921000003814697,cost_time=11384\n",
      "当前第3869回合，accuracy=0.9901000261306763,cost_time=11423\n",
      "当前第3879回合，accuracy=0.9919999837875366,cost_time=11462\n",
      "当前第3889回合，accuracy=0.9911999702453613,cost_time=11499\n",
      "当前第3899回合，accuracy=0.9919000267982483,cost_time=11538\n",
      "当前第3909回合，accuracy=0.9926000237464905,cost_time=11573\n",
      "当前第3919回合，accuracy=0.9922000169754028,cost_time=11607\n",
      "当前第3929回合，accuracy=0.9908999800682068,cost_time=11642\n",
      "当前第3939回合，accuracy=0.9919999837875366,cost_time=11674\n",
      "当前第3949回合，accuracy=0.9916999936103821,cost_time=11704\n",
      "当前第3959回合，accuracy=0.9911999702453613,cost_time=11734\n",
      "当前第3969回合，accuracy=0.9915000200271606,cost_time=11765\n",
      "当前第3979回合，accuracy=0.9916999936103821,cost_time=11795\n",
      "当前第3989回合，accuracy=0.9925000071525574,cost_time=11827\n",
      "当前第3999回合，accuracy=0.9926999807357788,cost_time=11861\n",
      "当前第4009回合，accuracy=0.9901999831199646,cost_time=11891\n",
      "当前第4019回合，accuracy=0.9919999837875366,cost_time=11922\n",
      "当前第4029回合，accuracy=0.9912999868392944,cost_time=11959\n",
      "当前第4039回合，accuracy=0.9916999936103821,cost_time=11993\n",
      "当前第4049回合，accuracy=0.9925000071525574,cost_time=12026\n",
      "当前第4059回合，accuracy=0.9915000200271606,cost_time=12060\n",
      "当前第4069回合，accuracy=0.9916999936103821,cost_time=12096\n",
      "当前第4079回合，accuracy=0.9919999837875366,cost_time=12133\n",
      "当前第4089回合，accuracy=0.9914000034332275,cost_time=12169\n",
      "当前第4099回合，accuracy=0.9901999831199646,cost_time=12203\n",
      "当前第4109回合，accuracy=0.9904999732971191,cost_time=12234\n",
      "当前第4119回合，accuracy=0.9909999966621399,cost_time=12266\n",
      "当前第4129回合，accuracy=0.9882000088691711,cost_time=12297\n",
      "当前第4139回合，accuracy=0.9911999702453613,cost_time=12326\n",
      "当前第4149回合，accuracy=0.9890999794006348,cost_time=12357\n",
      "当前第4159回合，accuracy=0.9912999868392944,cost_time=12388\n",
      "当前第4169回合，accuracy=0.9916999936103821,cost_time=12418\n",
      "当前第4179回合，accuracy=0.9919999837875366,cost_time=12449\n",
      "当前第4189回合，accuracy=0.9912999868392944,cost_time=12484\n",
      "当前第4199回合，accuracy=0.9915000200271606,cost_time=12519\n",
      "当前第4209回合，accuracy=0.9918000102043152,cost_time=12551\n",
      "当前第4219回合，accuracy=0.9925000071525574,cost_time=12583\n",
      "当前第4229回合，accuracy=0.9921000003814697,cost_time=12615\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-10-5476b5f74b81>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m     13\u001b[0m \u001b[1;31m#               .format( step, accuracy, cross_entropy_value, l2_loss_value, total_loss_value, int(time.time()-begin)))\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     14\u001b[0m     \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 15\u001b[1;33m         \u001b[0mtrain_step_value\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0msess\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrun\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mtrain_step\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfeed_dict\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m{\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mbatch_xs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my_\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mbatch_ys\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlearning_rate\u001b[0m\u001b[1;33m:\u001b[0m\u001b[0ml_r\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32mD:\\Develop\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36mrun\u001b[1;34m(self, fetches, feed_dict, options, run_metadata)\u001b[0m\n\u001b[0;32m    875\u001b[0m     \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    876\u001b[0m       result = self._run(None, fetches, feed_dict, options_ptr,\n\u001b[1;32m--> 877\u001b[1;33m                          run_metadata_ptr)\n\u001b[0m\u001b[0;32m    878\u001b[0m       \u001b[1;32mif\u001b[0m \u001b[0mrun_metadata\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    879\u001b[0m         \u001b[0mproto_data\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtf_session\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mTF_GetBuffer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mrun_metadata_ptr\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mD:\\Develop\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36m_run\u001b[1;34m(self, handle, fetches, feed_dict, options, run_metadata)\u001b[0m\n\u001b[0;32m   1098\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[0mfinal_fetches\u001b[0m \u001b[1;32mor\u001b[0m \u001b[0mfinal_targets\u001b[0m \u001b[1;32mor\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mhandle\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0mfeed_dict_tensor\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1099\u001b[0m       results = self._do_run(handle, final_targets, final_fetches,\n\u001b[1;32m-> 1100\u001b[1;33m                              feed_dict_tensor, options, run_metadata)\n\u001b[0m\u001b[0;32m   1101\u001b[0m     \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1102\u001b[0m       \u001b[0mresults\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mD:\\Develop\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36m_do_run\u001b[1;34m(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)\u001b[0m\n\u001b[0;32m   1270\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[0mhandle\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1271\u001b[0m       return self._do_call(_run_fn, feeds, fetches, targets, options,\n\u001b[1;32m-> 1272\u001b[1;33m                            run_metadata)\n\u001b[0m\u001b[0;32m   1273\u001b[0m     \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1274\u001b[0m       \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_do_call\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0m_prun_fn\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mhandle\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfeeds\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfetches\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mD:\\Develop\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36m_do_call\u001b[1;34m(self, fn, *args)\u001b[0m\n\u001b[0;32m   1276\u001b[0m   \u001b[1;32mdef\u001b[0m \u001b[0m_do_call\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfn\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1277\u001b[0m     \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1278\u001b[1;33m       \u001b[1;32mreturn\u001b[0m \u001b[0mfn\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1279\u001b[0m     \u001b[1;32mexcept\u001b[0m \u001b[0merrors\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mOpError\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1280\u001b[0m       \u001b[0mmessage\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mcompat\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mas_text\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0me\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmessage\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mD:\\Develop\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36m_run_fn\u001b[1;34m(feed_dict, fetch_list, target_list, options, run_metadata)\u001b[0m\n\u001b[0;32m   1261\u001b[0m       \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_extend_graph\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1262\u001b[0m       return self._call_tf_sessionrun(\n\u001b[1;32m-> 1263\u001b[1;33m           options, feed_dict, fetch_list, target_list, run_metadata)\n\u001b[0m\u001b[0;32m   1264\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1265\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0m_prun_fn\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mhandle\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfeed_dict\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfetch_list\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mD:\\Develop\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36m_call_tf_sessionrun\u001b[1;34m(self, options, feed_dict, fetch_list, target_list, run_metadata)\u001b[0m\n\u001b[0;32m   1348\u001b[0m     return tf_session.TF_SessionRun_wrapper(\n\u001b[0;32m   1349\u001b[0m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_session\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0moptions\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfeed_dict\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfetch_list\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtarget_list\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1350\u001b[1;33m         run_metadata)\n\u001b[0m\u001b[0;32m   1351\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1352\u001b[0m   \u001b[1;32mdef\u001b[0m \u001b[0m_call_tf_sessionprun\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mhandle\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfeed_dict\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfetch_list\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "# Train\n",
    "begin = time.time()\n",
    "for step in range(6000):\n",
    "    batch_xs, batch_ys = mnist.train.next_batch(100)\n",
    "    l_r = 0.1\n",
    "    \n",
    "    if (step+1) % 10 == 0:\n",
    "        train_step_value = sess.run(\n",
    "            [train_step], feed_dict={x: batch_xs, y_: batch_ys, learning_rate:l_r})\n",
    "        accuracy = get_accuracy(x, net, y_)\n",
    "        print(\"当前第{0}回合，accuracy={1},cost_time={2}\".format( step, accuracy, int(time.time()-begin)))\n",
    "#         print(\"当前第{0}回合，accuracy={1},cross_entropy_value={2}, l2_loss_value={3}, total_loss_value={4},cost_time={5}\"\n",
    "#               .format( step, accuracy, cross_entropy_value, l2_loss_value, total_loss_value, int(time.time()-begin)))\n",
    "    else:\n",
    "        train_step_value = sess.run([train_step], feed_dict={x: batch_xs, y_: batch_ys, learning_rate:l_r})"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "验证我们模型在测试数据上的准确率"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "毫无疑问，这个模型是一个非常简陋，性能也不理想的模型。目前只能达到92%左右的准确率。\n",
    "接下来，希望大家利用现有的知识，将这个模型优化至98%以上的准确率。\n",
    "Hint：\n",
    "- 卷积\n",
    "- 池化\n",
    "- 激活函数\n",
    "- 正则化\n",
    "- 初始化\n",
    "- 摸索一下各个超参数\n",
    "  - 卷积kernel size\n",
    "  - 卷积kernel 数量\n",
    "  - 学习率\n",
    "  - 正则化惩罚因子\n",
    "  - 最好每隔几个step就对loss、accuracy等等进行一次输出，这样才能有根据地进行调整"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
